#pragma once
#include "afxwin.h"
#include <vcclr.h>

// CFolderTreeCtrl


#define RFT_ALL (RFT_NAME | RFT_UNREAD_COUNT | RFT_STRUCTURE)

class CFolderTreeCtrl : public CTreeCtrl
{
	
	DECLARE_DYNAMIC(CFolderTreeCtrl)

public:
	CFolderTreeCtrl();
	virtual ~CFolderTreeCtrl();


private:
	BOOL m_bIsLableEditing;
	CImageList m_imageList;
    int RefreshFolderSubTree(HTREEITEM parentNode ,KingOfCSharp::iHunter::IFolder ^ parentFolder);
    void SetFolderTreeViewItem(KingOfCSharp::iHunter::IFolder^ folder,
        TVITEMEX *pItem, LPTSTR bufName, int bufLen,int unreadCount);
    int RefreshFolderNodeName(HTREEITEM hNode);

public:
	BEGIN_DELEGATE_MAP(CFolderTreeCtrl)
		EVENT_DELEGATE_ENTRY(OnMessageChanged, System::Object^, KingOfCSharp::iHunter::MessageEventArgs ^)
		EVENT_DELEGATE_ENTRY(OnFolderChanged, System::Object^, KingOfCSharp::iHunter::FolderEventArgs ^)
	END_DELEGATE_MAP()	

	void OnMessageChanged(System::Object ^sender, KingOfCSharp::iHunter::MessageEventArgs ^e);
	void OnFolderChanged(System::Object ^sender, KingOfCSharp::iHunter::FolderEventArgs ^e);
	
	void ExpandTree(HTREEITEM hItem);  
	void Refresh(BOOL refreshNodes = TRUE);
	afx_msg void OnTvnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	int InsertFolderNode(HTREEITEM parent, KingOfCSharp::iHunter::IFolder ^ folder);
	afx_msg void OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult);
	//afx_msg void OnTvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
	DECLARE_MESSAGE_MAP()
public:
	System::Guid GetSelectedFolderGuid();

	afx_msg void OnTvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTvnBeginlabeledit(NMHDR *pNMHDR, LRESULT *pResult);
};


